from wtforms import StringField,Form
from wtforms.validators import ValidationError,Length
from models.books import BoardModel


class BoardForm(Form):
    name = StringField(validators=[Length(min=1,max=20,message="请输入合适长度的名称")])

    def validate_name(self,filed):
            boards = BoardModel.query.all()
            for board in boards:
                if board.name == filed.data:
                    raise ValidationError(message="该分类名已存在")
